﻿using System;
using System.Windows;
#if WPF
using System.Windows.Data;
using System.Windows.Shapes;
#else
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Shapes;
using Windows.UI.Xaml.Data;
using Windows.Foundation;
#endif
namespace Eternal.DataVisualization
{
    public class StepAreaSeries : AxisType
    {
        internal override void UpdateRange()
        {
            base.UpdateRange();
            if (YAxis != null)
                YAxis.ActualStart = 0;
        }

        protected internal override void OnDrawSegment()
        {
            base.OnDrawSegment();
            SegmentPanel.Children.Clear();
            var line = new Polyline();
            SegmentPanel.Children.Add(line);
            ApplyBrush(line, 0);
            var dataCount = ActualXData.Count - 1;
            line.Points.Add(new Point(ValueToCoordianteXAxis(0), ValueToCoordianteYAxis(MinimumY)));
            for (var i = 0; i < dataCount; i++)
            {
                line.Points.Add(new Point(ValueToCoordianteXAxis(i), ValueToCoordianteYAxis(ActualYData[i])));
                line.Points.Add(new Point(ValueToCoordianteXAxis(i + 1), ValueToCoordianteYAxis(ActualYData[i])));
                line.Points.Add(new Point(ValueToCoordianteXAxis(i + 1), ValueToCoordianteYAxis(ActualYData[i + 1])));
            }
            line.Points.Add(new Point(ValueToCoordianteXAxis(dataCount), ValueToCoordianteYAxis(MinimumY)));
        }
    }
}
